package main

import (
	"fmt"
	"reflect"
)

type User struct {
	Name     string
	Password string
}

func (u *User) Login(name, password string) bool {
	return true
}

func (u *User) LoginOut(name, password string) bool {
	return true
}

func RPCCall(u *User, method string, params ...interface{}) []reflect.Value {
	t := reflect.TypeOf(u)
	if _, ok := t.MethodByName(method); ok {
		var vals []reflect.Value
		for _, p := range params {
			val := reflect.ValueOf(p)
			vals = append(vals, val)
		}
		return reflect.ValueOf(u).MethodByName(method).Call(vals)
	}
	return nil
}

func main() {
	u := &User{}
	result := RPCCall(u, "LoginOut", "tom", "123456") // 第二个参数Login是我们要调用的函数（方法）
	if result != nil && result[0].Interface() != nil {
		fmt.Println("success login")
	} else {
		fmt.Println("fail login")
	}
}
